import {get, post, UUID} from "@/utils/index";

export const uuid = UUID();

export const URLS = {
    TOKEN_READ: '/aiclz/speech/token/read',    //获取TOKEN
    ASK_INIT: 'https://aiclass.hireai.ai/asi/intro',                 //提问初始化
    ASK_1: 'https://aiclass.hireai.ai/asi/ask1',                  //提问
    ASK_2: 'https://aiclass.hireai.ai/asi/ask2',                  //提问
    AUDCR: '/aiclz/speech/create',         //生成音频
    AUD_CR_EMP: '/aiclz/speech/crempty',         //生成音频
    REC: '/aiclz/speech/recognizer',       //录音识别
    WSO: 'wss://nls-gateway.cn-shanghai.aliyuncs.com/ws/v1?token=',        //SOCKET
};

export const audios = {
    //嗯
    A1: 'http://xiaosaas.oss-cn-beijing.aliyuncs.com/1461096e-9559-402e-b7be-93c8ca0329f5-cb0b92587a8da2634d15c848d7cfb8fc-2.mp3',
    //好像出错了，请重新提问
    A2: 'http://xiaosaas.oss-cn-beijing.aliyuncs.com/e34980da-7b46-4d51-8378-5d5e0f6859de-1cd1cc515478f28d08f5b1b380999d62-2.mp3',
    //好的，那我们继续这节课的教学
    A3: 'http://xiaosaas.oss-cn-beijing.aliyuncs.com/b54258ca-3372-43ac-9abd-9a5cabb2ca41-cddccbc528a2f8bea36d01500acc4ae2-2.mp3',
    //刚才，我们讲到了：
    A4: 'http://xiaosaas.oss-cn-beijing.aliyuncs.com/fe1c56e1-979d-41a4-9374-6445aa3acf11-1b1ec035401cf15c4aec167152e5e97e-2.mp3',
    //那，还有其他问题吗？
    A5: 'http://xiaosaas.oss-cn-beijing.aliyuncs.com/abb0d45a-cccd-42c7-bea9-6a7f04e7c8ed-47a602f8f4e0e00aabc88c454843adbc-2.mp3',
    //这节课就上到这里吧，有什么问题，你还可以继续提问
    A6: 'http://xiaosaas.oss-cn-beijing.aliyuncs.com/5a110c4f-4bbe-4510-97d4-b7fc0b2c79f8-9aeb68180a90d378dd415a8ad1040e9a-2.mp3',
    //这节课我们来学习：
    A7: 'http://xiaosaas.oss-cn-beijing.aliyuncs.com/2e72e12e-fb6e-4804-9f9f-b133d8ee996c-147ba27d86631f015d2b4c8cac632efa-2.mp3',
}

export function getToken(){
    return new Promise((resolve, reject) => {
        get(URLS.TOKEN_READ).then((res) => {
            if(res.success && res.data){
                resolve(res)
            }else{
                reject(res)
            }
        }).catch(reject)
    })
}

export function getAudioUrl(){
   return post(URLS.AUD_CR_EMP, {uuid: uuid})
}

export function getAudio(text, type){
    return new Promise((resolve, reject) => {
        post(URLS.AUDCR,{text: text.replace(/<a[^<>]*>[^<>]*<\/a>/gi,''),uuid: uuid, type: type}).then((res) => {
            if(res.success && res.data){
                resolve(res.data)
            }else{
                reject(res)
            }
        }).catch(reject)
    })
}

export function ask(text, type){
    return new Promise((resolve, reject) => {
        post(URLS.ASK_2, {uid: uuid, msg: text, type: type}).then((res) => {
            if(res.success && res.data){
                resolve(res.data)
            }else{
                reject(res)
            }
        }).catch(reject)
    })

}

export function audioToText(url){
    return new Promise((resolve, reject) => {
        post(URLS.REC, {url}).then((res) => {
            if(res.success){
                resolve(res.data)
            }else{
                reject(res)
            }
        }).catch(reject)
    })
}